<template>
  <div class="my-goods-item">
    <div class="left">
      <div class="custom-control custom-checkbox">
        <input type="checkbox" class="custom-control-input"
        v-model="state" :id="goods.id">
        <label class="custom-control-label" :for="goods.id">
          <img :src="goods.goods_img" alt="">
        </label>
      </div>
    </div>
    <div class="right">
      <div class="top">{{ goods.goods_name }}</div>
      <div class="bottom">
        <span class="price">¥ {{ goods.goods_price }}</span>
        <span>
           <MyCount
           :goods_count="goods.goods_count"
           :id="goods.id"
           @changeCount="changeCount"
           @changeCountNum="changeCountNum"
           ></MyCount>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import  MyCount from './MyCount.vue'
export default {
    name:'MyGoods',
components:{
    MyCount
},
data(){
    return {
      
    }
},
props:{
    goods:{
        Type:Object,
        require:true //必选项
    }
},
methods: {
changeCount(isAddOrMinus,id){
    isAddOrMinus=='add'? this.$emit('changeCount','add',id) :this.$emit('changeCount','minus',id)
},
changeCountNum(num,id){
    this.$emit('changeCountNum',num,id)
}
},
computed:{
    state:{
        set(){
            this.$emit('changeState',this.goods.id)
        },
        get(){
            return this.goods.goods_state
        }
    }
}
}
</script>

<style lang="less" scoped>
.my-goods-item {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  .left {
    img {
      width: 120px;
      height: 120px;
      margin-right: 8px;
      border-radius: 10px;
    }
    .custom-control-label::before,
    .custom-control-label::after {
      top: 50px;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top{
        font-size: 14px;
        font-weight: 700;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      padding: 5px 0;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
}

</style>